<?php
/**
 * 美食TAG管理 - 编辑TAG
 *
 * @copyright dongping
 * @since 2012-03-24
 */


include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();



function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	cgi::both($g_cgival["turn_in"], "turn_in", 0);
	if ($g_cgival["turn_in"] != 1)
	{
		$g_cgival["turn_in"] = 0;
	}
	
	
	// 搜索词
	cgi::both($g_cgival["tag"], "tag", "");
	$g_cgival["tag"] = string::un_script_code($g_cgival["tag"]);
	$g_cgival["tag"] = string::un_html($g_cgival["tag"]);
	

}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	$g_show = $g_cgival;
	
	
	$tag = $g_cgival["tag"];
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();	// 拿到当前站点的site_id
	$admin_id = admin::admin_get_login_uid();	// 拿到当前管理员ID
	$admin_name = admin::admin_get_login_user_name();	// 拿到当前管理员用户名

	
	$tag_in_class = array();
	$db = new db_food_tag();
	$data = $db->admin_get_list_by_tags_ary($site_id, array($tag));
	if (is_array($data))
	{
		foreach($data as $k => $v)
		{
			$tag_in_class[$v["tag_class"]] = 1;
		}
	}
	
	
	$tag_class_ary = $config["food_tag_class"];
	foreach($tag_class_ary as $k =>$v)
	{
		$tag_class = $v;
		$tag_class_ary[$k] = array();
		$tag_class_ary[$k]["class"] = $v;
		if (array_key_exists($tag_class, $tag_in_class))
		{

			$tag_class_ary[$k]["tag_in_class"] = 1;
		}
	}
	
	
	$g_show["data"] = $tag_class_ary;
}




try
{
	admin_check_login();
	// 	admin_check_user_priv("foodv2/main_nav.php");

	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;

	if (isset($_GET["debug"]))
	{
		echo "<pre>";
		print_r($g_show);
	}

	global $g_show;
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	$smarty->display ( "foodv2/tag/tag_item_edit.html" );
}